ABC276 D - Divide by 2 or 3
提出
code: python
n = int(input())
a = list(map(int, input().split()))
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append((i, cnt))
if temp!=1:
arr.append((temp, 1))
if arr==[]:
arr.append((n, 1))
return arr
af = []
for i in a:
af.append(factorization(i))
# ベースが何になるか
print(af)
解答
code: python
from math import gcd
n = int(input())
a = list(map(int,input().split()))
g = 0
for i in range(n):
ans = 0
for i in range(n):
while now % 2 == 0:
now //= 2
ans += 1
while now % 3 == 0:
now //= 3
ans += 1
if now != 1:
print(-1)
exit()
print(ans)
テーマ
メモ
提出
code: python
n = int(input())
a = list(map(int, input().split()))
a.sort()
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
if temp != 1:
if arr == []:
return arr
print(af)
ex = []
one = 0
two = 0
three = 0
for afi in af:
for i, v in afi:
if i != 1 and i != 2 and i != 3:
if i == 1:
one += v
if i == 2:
two += v
if i == 3:
three += v
print(ex)
print(one, two, three)